package com.futvan.z.shop.order;

import com.futvan.z.framework.common.bean.Result;
import com.futvan.z.framework.core.z;
import org.springframework.stereotype.Service;
import com.futvan.z.framework.core.SuperService;

import java.util.List;

@Service
public class OrderService extends SuperService {

    /**
     * 保存订单
     *
     * @return
     */
    public Result insertProduct(s_order o) {
        if (z.isNotNull(o)) {
            List<s_order_products> oplist = (List<s_order_products>) o.getDetails().get("oplist");

            for (s_order_products p : oplist) {
                int n = sqlSession.insert("s_order_products_insert", p);
                if (n != 1) {
                    return Result.error("创建订单出错|保存订单产品明细出错");
                }
            }

            int n = sqlSession.insert("s_order_insert", o);
            if (n != 1) {
                return Result.error("保存订单出错");
            }

            return Result.success();
        }
        return Result.error();
    }
}
